//
//  ByCellServiceGood.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/7.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellServiceGood.h"

// vc
#import "ByServiceGoodServiceDetailVC.h"

@implementation ByCellServiceGood
{
    UIImageView *_imageView1;   // 左上
    UIImageView *_imageView2;   // 右上-上
    UIImageView *_imageView3;   // 右上-左下
    UIImageView *_imageView4;   // 右上-右下
    UIImageView *_imageView5;   // 右下
    UIImageView *_imageView6;   // 左下-上
    UIImageView *_imageView7;   // 左下-左下
    UIImageView *_imageView8;   // 左下-右下
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    _imageView1 = [self imageViewWithTitle];
    _imageView2 = [self imageViewWithTitle];
    _imageView3 = [self imageViewWithTitle];
    _imageView4 = [self imageViewWithTitle];
    _imageView5 = [self imageViewWithTitle];
    _imageView6 = [self imageViewWithTitle];
    _imageView7 = [self imageViewWithTitle];
    _imageView8 = [self imageViewWithTitle];
    
    _imageView1.tag = 0;
    _imageView2.tag = 1;
    _imageView3.tag = 2;
    _imageView4.tag = 3;
    _imageView5.tag = 7;
    _imageView6.tag = 4;
    _imageView7.tag = 5;
    _imageView8.tag = 6;

    CGFloat margin = 5;
    [_imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@0);
        make.width.equalTo(@((SCREEN_WIDTH - 30) / 3));
        make.height.equalTo(_imageView1.mas_width).multipliedBy(2);
    }];
    [_imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imageView1.mas_right).offset(margin);
        make.top.equalTo(_imageView1);
        make.right.equalTo(@-10);
        make.bottom.equalTo(_imageView1.mas_centerY).offset(margin / 2);
    }];
    [_imageView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imageView2);
        make.top.equalTo(_imageView2.mas_bottom).offset(margin);
        make.bottom.equalTo(_imageView1);
        make.right.equalTo(_imageView2.mas_centerX).offset(-margin / 2);
    }];
    [_imageView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(_imageView3);
        make.left.equalTo(_imageView3.mas_right).offset(margin);
        make.right.equalTo(_imageView2);
    }];
    [_imageView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(_imageView1);
        make.right.equalTo(@-10);
        make.top.equalTo(_imageView1.mas_bottom).offset(5);
        make.bottom.equalTo(self.contentView);
    }];
    [_imageView6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imageView1);
        make.top.equalTo(_imageView5);
        make.size.equalTo(_imageView2);
    }];
    [_imageView7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(_imageView3);
        make.left.equalTo(_imageView6);
        make.top.equalTo(_imageView6.mas_bottom).offset(margin);
    }];
    [_imageView8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.top.equalTo(_imageView7);
        make.left.equalTo(_imageView7.mas_right).offset(margin);
    }];
    
    
    
}

- (UIImageView *)imageViewWithTitle {
    
    UIImageView *imageView = [UIImageView new];
    imageView.userInteractionEnabled = true;
    imageView.image = [UIImage imageNamed:@"头视图背景"];
    [self.contentView addSubview:imageView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchAction:)];
    [imageView addGestureRecognizer:tap];
    
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    label.font = FONT(14);
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor blackColor];
    label.tag = 100;
    [imageView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(@0);
        make.height.equalTo(@15);
    }];
    
    return imageView;
}


- (void)touchAction:(UITapGestureRecognizer *)tap {
    
    NSInteger index = tap.view.tag;
    
    ByServiceGoodServiceDetailVC *vc = [ByServiceGoodServiceDetailVC new];
    [((ByBaseVC *)self.viewController) by_normalPush:vc hasNavi:true];
}
@end
